home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / utils / gredarc / sample.c < prev    next >
C/C++ Source or Header  |  1993-03-12  |  9KB  |  468 lines

  1. /***********************************************************
  2. SAMPLE.C
  3.  
  4. March 5, 1993
  5. R. Dobbins
  6.  
  7. ***********************************************************/
  8.  
  9.  
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <bios.h>
  13. #include <dos.h>
  14. #include <string.h>
  15. #include <allcode.h>
  16.  
  17. #include "vga.h"
  18.  
  19. static IMAGE_ST *girl_image;
  20. static REPLAY_IMG *girl_curr;
  21. static REPLAY_IMG *girl_first;
  22. static int girl_ix = 0;
  23.  
  24.  
  25. static IMAGE_ST *girl2_image;
  26. static REPLAY_IMG *girl2_curr;
  27. static REPLAY_IMG *girl2_first;
  28. static int girl2_ix = 0;
  29.  
  30.  
  31. static IMAGE_ST *boy_image;
  32. static REPLAY_IMG *boy_curr;
  33. static REPLAY_IMG *boy_first;
  34. static int boy_ix = 0;
  35.  
  36. static IMAGE_ST *boy2_image;
  37. static REPLAY_IMG *boy2_curr;
  38. static REPLAY_IMG *boy2_first;
  39. static int boy2_ix = 0;
  40.  
  41.  
  42. #define NUMMOVE 120
  43.  
  44. static int girl_moves[NUMMOVE] = {
  45.  
  46.  
  47. M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,
  48. M_UPRIGHT,M_UPRIGHT,M_UPRIGHT,M_UPRIGHT,M_UPRIGHT,
  49. M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,
  50. M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,
  51. M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,
  52. M_DNRIGHT,M_DNRIGHT,M_DNRIGHT,M_DNRIGHT,M_DNRIGHT,
  53.  
  54. M_DOWN,M_DOWN,M_DOWN,M_DOWN,M_DOWN,
  55. M_DOWN,M_DOWN,M_DOWN,M_DOWN,M_DOWN,
  56.  
  57. M_DNLEFT,M_DNLEFT,M_DNLEFT,M_DNLEFT,M_DNLEFT,
  58. M_LEFT,M_LEFT,M_LEFT,M_LEFT,M_LEFT,
  59. M_LEFT,M_LEFT,M_LEFT,M_LEFT,M_LEFT,
  60. M_LEFT,M_LEFT,M_LEFT,M_LEFT,M_LEFT,
  61. M_LEFT,M_LEFT,M_LEFT,M_LEFT,M_LEFT,
  62. M_UPLEFT,M_UPLEFT,M_UPLEFT,M_UPLEFT,M_UPLEFT,
  63.  
  64. M_UP,M_UP,M_UP,M_UP,M_UP,
  65. M_UP,M_UP,M_UP,M_UP,M_UP,
  66.  
  67. M_LEFT,M_LEFT,M_LEFT,M_LEFT,M_LEFT,
  68. M_LEFT,M_LEFT,M_LEFT,M_LEFT,M_LEFT,
  69.  
  70. M_DOWN,M_DOWN,M_DOWN,M_DOWN,M_DOWN,
  71. M_DOWN,M_DOWN,M_DOWN,M_DOWN,M_DOWN,
  72.  
  73. M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,
  74. M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,
  75.  
  76. M_UP,M_UP,M_UP,M_UP,M_UP,
  77. M_UP,M_UP,M_UP,M_UP,M_UP};
  78.  
  79.  
  80.  
  81. static int boy_moves[NUMMOVE] = {
  82.  
  83. M_LEFT,M_LEFT,M_LEFT,M_LEFT,M_LEFT,
  84. M_DNLEFT,M_DNLEFT,M_DNLEFT,M_DNLEFT,M_DNLEFT,
  85. M_LEFT,M_LEFT,M_LEFT,M_LEFT,M_LEFT,
  86. M_LEFT,M_LEFT,M_LEFT,M_LEFT,M_LEFT,
  87. M_LEFT,M_LEFT,M_LEFT,M_LEFT,M_LEFT,
  88. M_UPLEFT,M_UPLEFT,M_UPLEFT,M_UPLEFT,M_UPLEFT,
  89.  
  90. M_DOWN,M_DOWN,M_DOWN,M_DOWN,M_DOWN,
  91. M_DOWN,M_DOWN,M_DOWN,M_DOWN,M_DOWN,
  92.  
  93. M_UPRIGHT,M_UPRIGHT,M_UPRIGHT,M_UPRIGHT,M_UPRIGHT,
  94. M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,
  95. M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,
  96. M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,
  97. M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,
  98. M_DNRIGHT,M_DNRIGHT,M_DNRIGHT,M_DNRIGHT,M_DNRIGHT,
  99.  
  100. M_UP,M_UP,M_UP,M_UP,M_UP,
  101. M_UP,M_UP,M_UP,M_UP,M_UP,
  102.  
  103. M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,
  104. M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,M_RIGHT,
  105.  
  106. M_DOWN,M_DOWN,M_DOWN,M_DOWN,M_DOWN,
  107. M_DOWN,M_DOWN,M_DOWN,M_DOWN,M_DOWN,
  108.  
  109. M_LEFT,M_LEFT,M_LEFT,M_LEFT,M_LEFT,
  110. M_LEFT,M_LEFT,M_LEFT,M_LEFT,M_LEFT,
  111.  
  112. M_UP,M_UP,M_UP,M_UP,M_UP,
  113. M_UP,M_UP,M_UP,M_UP,M_UP};
  114.  
  115.  
  116.  
  117.  
  118.  
  119. static void move_girl(void)
  120. {
  121.  
  122. girl_image->data = girl_curr->image_data;
  123. check_move(girl_image,girl_moves[girl_ix]);
  124. girl_curr = girl_curr->next;
  125.  
  126. if (girl_curr == NULL)
  127.     girl_curr = girl_first;
  128.  
  129. if (girl_ix+1 < NUMMOVE)
  130.     {
  131.     girl_ix++;
  132.  
  133.     if (girl_ix == 45)
  134.         {
  135.         change_level(girl_curr->image_data,girl_image->row,
  136.                 girl_image->col,girl_image->height,girl_image->width,
  137.                 girl_image->level,5);
  138.  
  139.         girl_image->level = 5;
  140.         }
  141.  
  142.     }
  143. else
  144.     {
  145.     girl_ix = 0;
  146.  
  147.     change_level(girl_curr->image_data,girl_image->row,
  148.                 girl_image->col,girl_image->height,girl_image->width,
  149.                 girl_image->level,1);
  150.  
  151.     girl_image->level = 1;
  152.     }
  153.  
  154.  
  155. }
  156.  
  157.  
  158.  
  159.  
  160.  
  161. static void move_girl2(void)
  162. {
  163.  
  164. girl2_image->data = girl2_curr->image_data;
  165. check_move(girl2_image,girl_moves[girl2_ix]);
  166. girl2_curr = girl2_curr->next;
  167.  
  168. if (girl2_curr == NULL)
  169.     girl2_curr = girl2_first;
  170.  
  171.  
  172. if (girl2_ix+1 < NUMMOVE)
  173.     {
  174.     girl2_ix++;
  175.  
  176.     if (girl2_ix == 45)
  177.         {
  178.         change_level(girl2_image->data,girl2_image->row,
  179.             girl2_image->col,girl2_image->height,girl2_image->width,
  180.             girl2_image->level,6);
  181.  
  182.         girl2_image->level = 6;
  183.         }
  184.  
  185.     }
  186. else
  187.     {
  188.     girl2_ix = 0;
  189.  
  190.     change_level(girl2_image->data,girl2_image->row,
  191.             girl2_image->col,girl2_image->height,girl2_image->width,
  192.             girl2_image->level,2);
  193.  
  194.     girl2_image->level = 2;
  195.     }
  196.  
  197.  
  198. }
  199.  
  200.  
  201.  
  202.  
  203.  
  204. static void move_boy(void)
  205. {
  206.  
  207. boy_image->data = boy_curr->image_data;
  208. check_move(boy_image,boy_moves[boy_ix]);
  209. boy_curr = boy_curr->next;
  210.  
  211. if (boy_curr == NULL)
  212.     boy_curr = boy_first;
  213.  
  214. if (boy_ix+1 < NUMMOVE)
  215.     boy_ix++;
  216. else
  217.     boy_ix = 0;
  218.  
  219. }
  220.  
  221.  
  222. static void move_boy2(void)
  223. {
  224.  
  225. boy2_image->data = boy2_curr->image_data;
  226. check_move(boy2_image,boy_moves[boy2_ix]);
  227. boy2_curr = boy2_curr->next;
  228.  
  229. if (boy2_curr == NULL)
  230.     boy2_curr = boy2_first;
  231.  
  232. if (boy2_ix+1 < NUMMOVE)
  233.     boy2_ix++;
  234. else
  235.     boy2_ix = 0;
  236.  
  237. }
  238.  
  239.  
  240. #define MUSL 45
  241.  
  242. NOTE_ST music[MUSL] = {
  243.  
  244. {5,4,4},            // e
  245. {4,4,4},            // d#
  246. {5,4,4},            // e
  247. {4,4,4},            // d#
  248.  
  249. {5,4,4},            // e
  250. {12,3,4},            // b
  251. {3,4,4},            // d
  252. {1,4,4},            // c
  253.  
  254. {10,3,4},            // a
  255. {5,2,4},            // e
  256. {10,2,4},            // a
  257. {1,3,4},            // c
  258.  
  259. {5,3,4},            // e
  260. {10,3,4},            // a
  261. {12,3,4},            // b
  262. {5,2,4},            // e
  263.  
  264. {9,2,4},            // g#
  265. {5,3,4},            // e
  266. {9,3,4},            // g#
  267. {12,3,4},            // b
  268.  
  269. {1,4,4},            // c
  270. {5,2,4},            // e
  271. {10,2,4},            // a
  272. {5,3,4},            // e
  273.  
  274. /*****************/
  275.  
  276. {5,4,4},            // e
  277. {4,4,4},            // d#
  278. {5,4,4},            // e
  279. {4,4,4},            // d#
  280.  
  281. {5,4,4},            // e
  282. {12,3,4},            // b
  283. {3,4,4},            // d
  284. {1,4,4},            // c
  285.  
  286. {10,3,4},            // a
  287. {5,2,4},            // e
  288. {10,2,4},            // a
  289. {1,3,4},            // c
  290.  
  291. {5,3,4},            // e
  292. {10,3,4},            // a
  293. {12,3,4},            // b
  294. {5,2,4},            // e
  295.  
  296. {9,2,4},            // g#
  297. {5,3,4},            // e
  298. {1,4,4},            // c
  299. {12,3,4},            // b
  300.  
  301. {10,3,8}};        // a
  302.  
  303.  
  304.  
  305. void app_start(int argc, unsigned char *argv[])
  306. {
  307. long nwait;
  308. double fps = 18.00;
  309. int x;
  310. int do_sound = 0;
  311.  
  312.  
  313. for (x=1;x<argc;x++)
  314.     {
  315.     if (!stricmp(argv[x],"/m"))
  316.         do_sound = 1;
  317.     else if (!strnicmp(argv[x],"/f:",3))
  318.         fps = atof(argv[x]+3);
  319.     }
  320.  
  321. if (fps <= 0)
  322.     {
  323.     tellerr("FPS must be > 0");
  324.     return;
  325.     }
  326.  
  327. nwait = (long) (onesec / fps);
  328.  
  329. load_scrn("stage.ggf");
  330.  
  331. if (!load_palette("sample.pal",0))
  332.     return;
  333.  
  334. if ((girl_first=load_sequence("girl.ggf")) == NULL)
  335.     return;
  336.  
  337. if ((girl_image=append_image(girl_first->image_data,60,80,
  338.             image_header.height,image_header.width,1))==NULL)
  339.     {
  340.     dealloc_seq(girl_first);
  341.     return;
  342.     }
  343.  
  344. girl_curr = girl_first;
  345. girl_image->data = girl_curr->image_data;
  346.  
  347.  
  348. if ((girl2_first=load_sequence("girl2.ggf")) == NULL)
  349.     return;
  350.  
  351. if ((girl2_image=append_image(girl2_first->image_data,60,190,
  352.             image_header.height,image_header.width,2))==NULL)
  353.     {
  354.     dealloc_seq(girl2_first);
  355.     return;
  356.     }
  357.  
  358. girl2_curr = girl2_first;
  359. girl2_image->data = girl2_curr->image_data;
  360.  
  361.  
  362. if ((boy_first=load_sequence("boy.ggf")) == NULL)
  363.     {
  364.     dealloc_all_images();
  365.     dealloc_seq(girl_first);
  366.     dealloc_seq(girl2_first);
  367.     return;
  368.     }
  369.  
  370. if ((boy_image=append_image(boy_first->image_data,60,113,
  371.             image_header.height,image_header.width,3))==NULL)
  372.     {
  373.     dealloc_all_images();
  374.     dealloc_seq(girl_first);
  375.     dealloc_seq(girl2_first);
  376.     dealloc_seq(boy_first);
  377.     return;
  378.     }
  379.  
  380. boy_curr = boy_first;
  381. boy_image->data = boy_curr->image_data;
  382.  
  383. if ((boy2_first=load_sequence("boy2.ggf")) == NULL)
  384.     {
  385.     dealloc_all_images();
  386.     dealloc_seq(girl_first);
  387.     dealloc_seq(girl2_first);
  388.     return;
  389.     }
  390.  
  391. if ((boy2_image=append_image(boy2_first->image_data,60,223,
  392.             image_header.height,image_header.width,4))==NULL)
  393.     {
  394.     dealloc_all_images();
  395.     dealloc_seq(girl_first);
  396.     dealloc_seq(girl2_first);
  397.     dealloc_seq(boy_first);
  398.     dealloc_seq(boy2_first);
  399.     return;
  400.     }
  401.  
  402. boy2_curr = boy2_first;
  403. boy2_image->data = boy2_curr->image_data;
  404.  
  405. colors_black();
  406. initmask();
  407.  
  408. if (screen_loaded)
  409.     showscrn();
  410. else
  411.     {
  412.     clrall(0x1);
  413.     initscrn();
  414.     }
  415.  
  416. showimage(girl_image->data,girl_image->level,
  417.                     girl_image->row,girl_image->col,
  418.                     girl_image->height,girl_image->width);
  419.  
  420. showimage(boy_image->data,boy_image->level,
  421.                     boy_image->row,boy_image->col,
  422.                     boy_image->height,boy_image->width);
  423.  
  424. showimage(girl2_image->data,girl2_image->level,
  425.                     girl2_image->row,girl2_image->col,
  426.                     girl2_image->height,girl2_image->width);
  427.  
  428. showimage(boy2_image->data,boy2_image->level,
  429.                     boy2_image->row,boy2_image->col,
  430.                     boy2_image->height,boy2_image->width);
  431.  
  432. fade_in();
  433. wait_to((long) onesec);
  434.  
  435. if (do_sound)
  436.     start_music(music,MUSL);
  437.  
  438. for (;;)
  439.     {
  440.     if (_bios_keybrd(1))
  441.         {
  442.         getkey();
  443.         if (allcode == K_ESC)
  444.             break;
  445.         }
  446.  
  447.     move_girl();
  448.     move_girl2();
  449.     move_boy();
  450.     move_boy2();
  451.     wait_to(nwait);
  452.     }
  453.  
  454.  
  455. if (do_sound)
  456.     quit_music();
  457.  
  458. fade_out();
  459. dealloc_all_images();
  460. dealloc_seq(girl_first);
  461. dealloc_seq(girl2_first);
  462. dealloc_seq(boy_first);
  463. dealloc_seq(boy2_first);
  464.  
  465. }
  466.  
  467.  
  468.